import React,{Component} from "react";
import {FlatList,Text} from "react-native";

export default class FlatListPage extends Component {
    constructor(){
        super();
        this.state = {
            listData:[],
            refreshing : false
        }
        for(var i = 0;i<300;i++){
            this.state.listData.push({key: 'list'+i});
        }
    }


    render() {
        return (
            <FlatList
                data= {this.state.listData}
                renderItem={({item}) => <Text style={{height:50}}>{item.key}</Text>}
                refreshing={this.state.refreshing}
                onRefresh = {()=>{
                    for(var i = 0;i<this.state.listData.length;i++){
                        var temp = this.state.listData[i];
                        temp.key = temp.key+i;
                        this.state.listData[i] = temp;
                    }
                    this.setState({refreshing : false});
                }}
                onEndReachedThreshold={0.01}
                onEndReached={(info)=>{
                    if(info.distanceFromEnd<0){//不满一个屏幕不然加载更多
                        return;
                    }
                    const temp = this.state.listData;
                    temp.push({key: 'list'+this.state.listData.length});
                }}
            />
        );
    }
}


